package hut.ai.team.actor;

import hut.ai.team.screen.MainScreen;
import hut.ai.team.table.NuocDi;

public class Eval {
	public int[] SCORE = {10,120,120,270,285,600,6000};
	public int[] DEFENCE = {2,4,4,8,9,18,0};
	public int[] ATTACK = {4,8,8,16,17,32};
	public int[] UP = {15,7,7,10,12,3,0};
	
	Gen mGen;
	
	public int UocLuong(){
		int tong = 0, max = 0, min = 0;
		if (MainScreen.getInstance().mode == 1) {
			for(int i = 0; i < MainScreen.getInstance().computer.dsQuanCo.size(); i++){
				min +=  (MainScreen.getInstance().computer.dsQuanCo.get(i)).getDiem();
			}

			for(int i = 0; i < MainScreen.getInstance().n1.dsQuanCo.size(); i++){
				max +=  (MainScreen.getInstance().n1.dsQuanCo.get(i)).getDiem();
			}
		}
		tong = max - min;
		return  tong;
	}
	
	public int TinhDiemBanCo(NuocDi mNuocDi){
		mGen = new Gen();
		mGen.MakeMove(mNuocDi);
		int tong = 0, max = 0, min = 0;
		if (MainScreen.getInstance().mode == 1) {
			for(int i = 0; i < MainScreen.getInstance().computer.dsQuanCo.size(); i++){
				max +=  (MainScreen.getInstance().computer.dsQuanCo.get(i)).getDiem();
			}

			for(int i = 0; i < MainScreen.getInstance().n1.dsQuanCo.size(); i++){
				min +=  (MainScreen.getInstance().n1.dsQuanCo.get(i)).getDiem();
			}
		}
		tong = max - min;
		mGen.UnMakeMove(mNuocDi);
		return tong;
	}
	
	public int TinhTongDiemBanCo() {
		int tong = 0, max = 0, min = 0;
		if (MainScreen.getInstance().mode == 1) {
			for(int i = 0; i < MainScreen.getInstance().computer.dsQuanCo.size(); i++){
				if(MainScreen.getInstance().computer.dsQuanCo.get(i).TrangThai != 0)
					max +=  (MainScreen.getInstance().computer.dsQuanCo.get(i)).getDiem();
			}

			for(int i = 0; i < MainScreen.getInstance().n1.dsQuanCo.size(); i++){
				if(MainScreen.getInstance().n1.dsQuanCo.get(i).TrangThai != 0)
					min +=  (MainScreen.getInstance().n1.dsQuanCo.get(i)).getDiem();
			}
		}
		tong = max - min;
//		System.out.println("max/min [" + max+"/"+min + "/" + tong + "]");
		return  tong;
	}
	
	public int Bonous() {
		int[][] bonous = { { -2, -3, -3, -4, -4, -5, 0 }, /* Chot, Sy, Tinh, Ma, Phao, Xe, Tuong - Quan Den */
						   { -2, -3, -3, -4, -4, -5, 0 } /* Chot, Sy, Tinh, Ma, Phao, Xe, Tuong - Quan Do */
						 };
		int diemthuong = 0;

		// Tang diem cho quan doi phuong khi khuyet sy, tinh va tru diem khi xe,
		for(int i  = 0; i < MainScreen.getInstance().computer.dsQuanCo.size(); i++){
			if (MainScreen.getInstance().computer.dsQuanCo.get(i).TrangThai == 0 
					&& MainScreen.getInstance().computer.dsQuanCo.get(i).LoaiCL == 2  ) {
				bonous[0][5] += 4; // Tang diem cho xe, ma, chot
				bonous[0][3] += 2;
				bonous[0][0] += 1;
			}
			if (MainScreen.getInstance().computer.dsQuanCo.get(i).TrangThai == 0 
					&& MainScreen.getInstance().computer.dsQuanCo.get(i).LoaiCL == 3 ) {
				bonous[0][5] += 2; /* Tang diem cho xe, phao, chot */
				bonous[0][4] += 2;
				bonous[0][0] += 1;
			}
		}
		
		for(int i  = 0; i < MainScreen.getInstance().n1.dsQuanCo.size(); i++){
			if (MainScreen.getInstance().n1.dsQuanCo.get(i).TrangThai == 0 
					&& MainScreen.getInstance().n1.dsQuanCo.get(i).LoaiCL == 2  ) {
				bonous[1][5] += 4; // Tang diem cho xe, ma, chot
				bonous[1][3] += 2;
				bonous[1][0] += 1;
			}
			if (MainScreen.getInstance().n1.dsQuanCo.get(i).TrangThai == 0 
					&& MainScreen.getInstance().n1.dsQuanCo.get(i).LoaiCL == 3 ) {
				bonous[1][5] += 2; /* Tang diem cho xe, phao, chot */
				bonous[1][4] += 2;
				bonous[1][0] += 1;
			}
		}
		
		int[][] count = { { 0, 0, 0, 0, 0, 0, 0 }, /* Chot, Sy, Tinh, Ma, Phao, Xe, Tuong - Quan Den */
						  { 0, 0, 0, 0, 0, 0, 0 } }; /* Chot, Sy, Tinh, Ma, Phao, Xe, Tuong - Quan Do */
		
		for(int i = 0; i < MainScreen.getInstance().computer.dsQuanCo.size(); i++){
			if(MainScreen.getInstance().computer.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().computer.dsQuanCo.get(i).Loai == 7)
			{
				count[0][1] += 1;
			}
			if(MainScreen.getInstance().computer.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().computer.dsQuanCo.get(i).Loai == 6)
			{
				count[0][2] += 1;
			}
			if(MainScreen.getInstance().computer.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().computer.dsQuanCo.get(i).Loai == 5)
			{
				count[0][3] += 1;
			}
			if(MainScreen.getInstance().computer.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().computer.dsQuanCo.get(i).Loai == 4)
			{
				count[0][4] += 1;
			}
			if(MainScreen.getInstance().computer.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().computer.dsQuanCo.get(i).Loai == 3)
			{
				count[0][5] += 1;
			}
			if(MainScreen.getInstance().computer.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().computer.dsQuanCo.get(i).Loai == 2)
			{
				count[0][6] += 1;
			}
		}
		
		for(int i = 0; i < MainScreen.getInstance().n1.dsQuanCo.size(); i++){
			if(MainScreen.getInstance().n1.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().n1.dsQuanCo.get(i).Loai == 7)
			{
				count[1][1] += 1;
			}
			if(MainScreen.getInstance().n1.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().n1.dsQuanCo.get(i).Loai == 6)
			{
				count[1][2] += 1;
			}
			if(MainScreen.getInstance().n1.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().n1.dsQuanCo.get(i).Loai == 5)
			{
				count[1][3] += 1;
			}
			if(MainScreen.getInstance().n1.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().n1.dsQuanCo.get(i).Loai == 4)
			{
				count[1][4] += 1;
			}
			if(MainScreen.getInstance().n1.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().n1.dsQuanCo.get(i).Loai == 3)
			{
				count[1][5] += 1;
			}
			if(MainScreen.getInstance().n1.dsQuanCo.get(i).TrangThai != 0 
					&& MainScreen.getInstance().n1.dsQuanCo.get(i).Loai == 2)
			{
				count[1][6] += 1;
			}
		}
		for (int i = 0; i <= 5; i++) {
			diemthuong += count[0][i] * bonous[0][i] - count[1][i]* bonous[1][i];
		}
		// Tru diem khi mat quan
		diemthuong += bonous[0][6] - bonous[1][6];
		return diemthuong;
	}
	
}
